package com.example.mydemo103;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.example.mydemo103.ui.borrowbook.borrowFragment;
import com.example.mydemo103.ui.person.personFrgment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        BottomNavigationView navView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navigation_home, R.id.rankmun, R.id.bookstory,R.id.person)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(navView, navController);


        Bundle bundle = new Bundle();
        bundle.putString("bookimg", "1");
//                bundle.putString("", userNames);
        borrowFragment fragment1 = new borrowFragment();
        fragment1.setArguments(bundle);
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.nav_host_fragment,fragment1);



        int id = getIntent().getIntExtra("imgID", 0);
        if (id == 1) {
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.nav_host_fragment,new borrowFragment())
                    .addToBackStack(null)
                    .commit();
        }
        //    去除标题栏
        if (getSupportActionBar() != null){
            getSupportActionBar().hide();
        }

//        接受intent传输过来的Extra值
//        int id = getIntent().getIntExtra("id", 0);
//        if (id == 1) {
//            getSupportFragmentManager()
//                    .beginTransaction()
//                    .replace(R.id.navigation_home,new personFrgment())
//                    .addToBackStack(null)
//                    .commit();
//        }
    }

    @Override
    protected void onPause() {
        super.onPause();
//        finish();
    }
}